// base
import Taro, { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
// redux
import { connect } from '@tarojs/redux'
import { DOREQUESTNEWWORKEXP } from './store/actions/pagenewworkexp'
import { UPDATEPAGENEWWORKEXP } from './store/types/pagenewworkexp'
// less
import './index.less'

// componnet
import NetworkError from '../../components/taro-ui/network-error'
// libs
import WorkExpCard from '../../components/page-components/work-exp-card'
import { navigateTo } from '../../crossplatform/apiservice/navigate'
import { pagejumplist } from '../../configuration/pagejump'
import BtmFixedBtn from '../../components/page-components/btm-fixed-btn'

const mapActiontoProps = dispatch => ({
  updateState (payload) {
    dispatch({
      type: UPDATEPAGENEWWORKEXP,
      payload: {
        ...payload
      }
    })
  },
  dorequest (payload) {
    return new Promise(resolve => {
      let promise = DOREQUESTNEWWORKEXP(payload)
      dispatch(promise)
      promise.payload.then(data => {
        resolve(data)
      })
    })
  }
})

@connect(
  ({ pagenewworkexp, userinfo }) => ({
    ...pagenewworkexp,
    userId: userinfo.userId
  }),
  mapActiontoProps
)
class NewWorkExp extends Component {
  config = {
    navigationBarTitleText: '工作经验'
  }

  componentWillMount () {
    // onLoad
  }

  componentDidMount () {
    // onready
  }

  componentDidShow () {
    // onshow
    this.queryWrap()
  }

  componentDidHide () {
    // onhide
  }

  componentWillUnmount () {
    // onUnload
  }

  queryWrap = () => {
    const { userId } = this.props
    this.props.dorequest({ userId })
  }

  jumpTo = id => {
    navigateTo({
      url: `${pagejumplist['work-exp'].path}?id=${id}`
    })
  }

  onTap = () => {
    navigateTo({
      url: pagejumplist['work-exp'].path
    })
  }

  render () {
    const { workExp } = this.props
    return (
      <View className="NewWorkExp_id60924">
        <View className="title">工作经验</View>
        {workExp.map((data, index) => {
          return (
            <View className="card">
              <WorkExpCard onTap={this.jumpTo} dataSource={data} />
            </View>
          )
        })}
        <BtmFixedBtn text="添加工作经验" onTap={this.onTap} />
      </View>
    )
  }
}

export default NewWorkExp
